<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateNewsTable extends Migration
{
    /**
     * Run the migrations.
     * @return void
     */
    public function up()
    {
        Schema::create('news_class', function (Blueprint $table) {
            $table->string('id', 20)->primary();
            $table->unsignedInteger('sortnum')->default(0)->comment('同级序号');
            $table->string('order_by', 20)->default('')->comment('多级序号');
            $table->string('name', 50)->default('')->comment('栏目名称');
            $table->string('pic1', 100)->default('')->comment('图片');
            $table->string('url', 100)->default('')->comment('链接');
            $table->string('sort_by', 10)->default('')->comment('排序:ASC升度/DESC降序');
            $table->tinyInteger('depth')->default(0)->comment('栏目深度');
            $table->tinyInteger('mode')->default(0)->comment('显示模式');
            $table->tinyInteger('allow_add')->default(0)->comment('允许增加子栏目');
            $table->tinyInteger('allow_edit')->default(0)->comment('允许编辑栏目');
            $table->tinyInteger('allow_del')->default(0)->comment('允许删除栏目');
            $table->tinyInteger('has_subtitle')->default(0)->comment('有无副标题');
            $table->tinyInteger('has_tags')->default(0)->comment('有无标签');
            $table->tinyInteger('has_intro')->default(0)->comment('有无简介');
            $table->tinyInteger('has_content')->default(0)->comment('有无内容');
            $table->tinyInteger('has_website')->default(0)->comment('有无网址');
            $table->tinyInteger('has_editor')->default(0)->comment('有无编辑');
            $table->tinyInteger('has_author')->default(0)->comment('有无作者');
            $table->tinyInteger('has_source')->default(0)->comment('有无来源');
            $table->tinyInteger('has_pic1')->default(0)->comment('有无图片');
            $table->tinyInteger('has_pic2')->default(0)->comment('有无大图');
            $table->tinyInteger('has_pics')->default(0)->comment('有无多图');
            $table->tinyInteger('has_file1')->default(0)->comment('有无附件');
            $table->tinyInteger('has_hot')->default(0)->comment('有无热点');
            $table->tinyInteger('has_new')->default(0)->comment('有无新品');
            $table->tinyInteger('has_top')->default(0)->comment('有无置顶');
            $table->tinyInteger('has_recommend')->default(0)->comment('有无推荐');
        });
        Schema::create('news_popedom', function (Blueprint $table) {
            $table->string('class_id', 20)->comment('标目Id');
            $table->integer('role_id')->unsigned()->comment('角色Id');
            $table->unsignedTinyInteger('popedom')->default(0)->comment('权限:1添加/2编辑/4审核/8删除');
            $table->foreign('class_id')->references('id')->on('news_class')
                ->onUpdate('cascade')->onDelete('cascade');
            $table->foreign('role_id')->references('id')->on('roles')
                ->onUpdate('cascade')->onDelete('cascade');
            $table->primary(['class_id', 'role_id']);
        });
        Schema::create('news_info', function (Blueprint $table) {
            $table->increments('id');
            $table->string('class_id', 20)->default('')->comment('栏目Id');
            $table->unsignedInteger('sortnum')->default(0)->comment('序号');
            $table->string('title', 100)->default('')->comment('标题');
            $table->string('subtitle', 100)->default('')->comment('副标题');
            $table->string('title_color', 10)->default('')->comment('标题颜色');
            $table->string('title_bold', 10)->default('')->comment('标题加粗');
            $table->string('first_letter', 1)->default('')->comment('标题首字母');
            $table->string('website', 100)->default('')->comment('网址');
            $table->string('tags', 200)->default('')->comment('标签');
            $table->string('author', 30)->default('')->comment('作者');
            $table->string('editor', 30)->default('')->comment('编辑');
            $table->string('source', 50)->default('')->comment('来源');
            $table->string('publish_at', 20)->default('')->comment('发布时间');
            $table->text('intro')->nullable()->comment('简介');
            $table->text('content')->nullable()->comment('内容');
            $table->string('pic1', 100)->default('')->comment('图片');
            $table->string('pic2', 100)->default('')->comment('大图');
            $table->string('file1', 100)->default('')->comment('附件');
            $table->tinyInteger('is_top')->default(0)->comment('是否置顶');
            $table->tinyInteger('is_new')->default(0)->comment('是否新品');
            $table->tinyInteger('is_hot')->default(0)->comment('是否热点');
            $table->tinyInteger('is_recommend')->default(0)->comment('是否推荐');
            $table->tinyInteger('is_locked')->default(0)->comment('是否锁定');
            $table->unsignedInteger('views')->default(0)->comment('浏览次数');
            $table->unsignedInteger('comments')->default(0)->comment('评论次数');
            $table->tinyInteger('status')->default(0)->comment('状态:0不显示/1显示');
            $table->unsignedInteger('created_user_id')->default(0)->comment('创建者');
            $table->unsignedInteger('updated_user_id')->default(0)->comment('最后修改者');
            $table->dateTime('created_at')->nullable()->comment('创建时间');
            $table->dateTime('updated_at')->nullable()->comment('更新时间');
            $table->foreign('class_id')->references('id')->on('news_class')
                ->onUpdate('cascade')->onDelete('cascade');
        });
        Schema::create('news_info_pics', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('info_id')->default(0)->comment('资讯Id');
            $table->string('title', 100)->default('')->comment('段落标题');
            $table->text('content')->nullable()->comment('段落内容');
            $table->string('pic1', 100)->default('')->comment('图片');
            $table->foreign('info_id')->references('id')->on('news_info')
                ->onUpdate('cascade')->onDelete('cascade');
        });
    }

    /**
     * Reverse the migrations.
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('news_popedom');
        Schema::dropIfExists('news_info_pics');
        Schema::dropIfExists('news_info');
        Schema::dropIfExists('news_class');
    }
}
